//
//  MemberWelfareLastlyCollectionViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/30.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MemberWelfareLastlyCollectionViewCell.h"

@interface MemberWelfareLastlyCollectionViewCell ()

@property (strong, nonatomic) UIView *bgView;

@property (strong, nonatomic) UIImageView *markIV;
@property (strong, nonatomic) UILabel *markL;

@property (strong, nonatomic) UIImageView *goodIV;
@property (strong, nonatomic) UILabel *titleL;
@property (strong, nonatomic) UILabel *priceL;
@property (strong, nonatomic) UILabel *qxtPriceL;

@property (strong, nonatomic) UIImageView *purchaseIV;
@property (strong, nonatomic) UILabel *purchaseL;

@end

@implementation MemberWelfareLastlyCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self.contentView addSubview:self.bgView];
        [self.contentView addSubview:self.goodIV];
        [self.contentView addSubview:self.titleL];
        [self.contentView addSubview:self.priceL];
        [self.contentView addSubview:self.qxtPriceL];
        [self.contentView addSubview:self.purchaseIV];
        [self.contentView addSubview:self.purchaseL];
        [self.contentView addSubview:self.markIV];
        [self.contentView addSubview:self.markL];
        
    }
    
    return self;
}
#pragma mark -立即购买点击
- (void)purchaseGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"立即购买");
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        
    }];
   
    [self.markL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.markIV.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.markIV.mas_centerY);
       
    }];
    [self.goodIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.height.mas_equalTo(jisuan(240));

    }];

    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(28));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(28));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(258));

    }];
    [self.priceL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(28));
 make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(136));

    }];
    [self.qxtPriceL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(28));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(96));

    }];
    [self.purchaseIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(30));
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(22));
        make.width.mas_equalTo(jisuan(156));
        make.height.mas_equalTo(jisuan(46));

    }];
    [self.purchaseL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.mas_equalTo(weakSelf.purchaseIV.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.purchaseIV.mas_centerY);

    }];

    [self.markIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(18));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(20));
        make.width.mas_equalTo(jisuan(100));
        make.height.mas_equalTo(jisuan(36));
    }];
}

- (void)setGoodListModel:(SupportCategoryGoodListModel *)goodListModel {
    
    NSString *urlString = @"";
    if ([goodListModel.goods_url hasPrefix:@"http://"] || [goodListModel.goods_url hasPrefix:@"https://"]) {
        urlString = goodListModel.goods_url;
    }else {
        urlString = [NSString stringWithFormat:@"http://%@",goodListModel.goods_url];
    }
    [self.goodIV sd_setImageWithURL:[NSURL URLWithString:urlString]];
    self.titleL.text = goodListModel.title;
    self.priceL.text = [NSString stringWithFormat:@"%.2f",[goodListModel.price floatValue] - [goodListModel.dintegral floatValue]];
    self.qxtPriceL.text = [NSString stringWithFormat:@"原价：%@",goodListModel.price];
}


#pragma mark -lazy
- (UIView *)bgView {
    
    if (!_bgView) {
        
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = WhiteColor;
        _bgView.layer.cornerRadius = jisuan(10);
        _bgView.layer.masksToBounds = YES;
        
    }
    
    return _bgView;
}

- (UIImageView *)markIV {
    
    if (!_markIV) {
        
        _markIV = [[UIImageView alloc] init];
        _markIV.contentMode = UIViewContentModeScaleAspectFit;
        _markIV.image = [UIImage imageNamed:@"recommendTodaybg"];
    }
    
    return _markIV;
}
- (UILabel *)markL {
    
    if (!_markL) {
        
        _markL = [[UILabel alloc] init];
        _markL.textColor = Colorf8e3ac;
        _markL.text = @"今日推荐";
        _markL.font = Font(20);
        _markL.textAlignment = NSTextAlignmentCenter;
        
    }
    
    return _markL;
}

- (UIImageView *)goodIV {
    
    if (!_goodIV) {
        
        _goodIV = [[UIImageView alloc] init];
        _goodIV.contentMode = UIViewContentModeScaleAspectFit;

    }
    
    return _goodIV;
}

- (UILabel *)titleL {
    
    if (!_titleL) {
        
        _titleL = [[UILabel alloc] init];
        _titleL.textColor = Color333333;
        _titleL.numberOfLines = 2;
        _titleL.font = Font(24);
        _titleL.textAlignment = NSTextAlignmentLeft;
        
        NSString *str = @"Nike Air Maestro II LTD男子运动鞋从经典篮球鞋款";
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = jisuan(3);
        [attributeStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, str.length)];
        _titleL.attributedText = attributeStr;
        
    }
    
    return _titleL;
}

- (UILabel *)priceL {
    
    if (!_priceL) {
        
        _priceL = [[UILabel alloc] init];
        _priceL.textColor = Color333333;
        
        NSString *str = @"￥ 949.00";
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        [attributeStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
        [attributeStr addAttribute:NSFontAttributeName value:Font(40) range:NSMakeRange(1, str.length - 1)];
        _priceL.attributedText = attributeStr;
        
//        _priceL.font = Font(40);
        _priceL.textAlignment = NSTextAlignmentLeft;
        
    }
    
    return _priceL;
}
- (UILabel *)qxtPriceL {
    
    if (!_qxtPriceL) {
        
        _qxtPriceL = [[UILabel alloc] init];
        _qxtPriceL.textColor = Color999999;
//        _qxtPriceL.text = @"价：1000.00";
        _qxtPriceL.font = Font(20);
        _qxtPriceL.textAlignment = NSTextAlignmentLeft;
        
    }
    
    return _qxtPriceL;
}

- (UIImageView *)purchaseIV {
        
    if (!_purchaseIV) {
        
        _purchaseIV = [[UIImageView alloc] init];
        _purchaseIV.contentMode = UIViewContentModeScaleAspectFit;
        _purchaseIV.image = [UIImage imageNamed:@"purchasePayBG"];
        _purchaseIV.userInteractionEnabled = YES;
        
        _purchaseIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *payOrderGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(purchaseGestureClick:)];
        [_purchaseIV addGestureRecognizer:payOrderGesture];
        
    }
    
    return _purchaseIV;

}
- (UILabel *)purchaseL {
    
    if (!_purchaseL) {
        
        _purchaseL = [[UILabel alloc] init];
        _purchaseL.textColor = WhiteColor;
        _purchaseL.text = @"立即抢购";
        _purchaseL.font = Font(24);
        _purchaseL.textAlignment = NSTextAlignmentCenter;
        
    }
    
    return _purchaseL;
}

@end
